const db = require('../mysql/db')
const jsonData = require('./tabsItem.json')
const dataArr = jsonData.result.list
dataArr.map((item, index) => {
    dbInsert(item, index)
})
function dbInsert(data, index) {
    const sqlInsert = `
    insert into tabs_item (id,category,pre,now,icon,name,info,specification,alcohol,description) values (?,?,?,?,?,?,?,?,?,?)
    `
    db.query(sqlInsert,
        [
            data.id,
            data.category,
            data.pre,
            data.now,
            data.icon,
            data.name,
            data.info,
            data.specification,
            data.alcohol,
            data.description
        ], (err, results) => {
            // 执行SQL语句失败
            if (err) return console.log(err.message);
            // 成功了
            if (results.affectedRows === 1) {
                console.log(`第${index}条数据插入成功!`);
            }
            if (index === dataArr.length - 1){
                db.end()
            }
            return
        })
}
